package com.haidechizi.i18n.common.entity;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections.CollectionUtils;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Data
@NoArgsConstructor
public class I18nEntity {

    private String systemCode;
    private String businessCode;
    private String businessKey;

    private List<Field> simpleFields;

    private List<Field> combinedFields;

    private List<Field> customFields;
    private List<Field> enumFields;
    private Map<String, List<Object>> objectMap = new HashMap<>();

    public I18nEntity(String systemCode, String businessCode, String businessKey) {
        this.systemCode = systemCode;
        this.businessCode = businessCode;
        this.businessKey = businessKey;
    }

    public I18nEntity(String systemCode, String businessCode, String businessKey, List<Field> simpleFields) {
        this.systemCode = systemCode;
        this.businessCode = businessCode;
        this.businessKey = businessKey;
        this.simpleFields = simpleFields;
    }

    public I18nEntity(String systemCode, String businessCode, String businessKey, List<Field> simpleFields,
                      List<Field> combinedFields, List<Field> customFields, List<Field> enumFields) {
        this.systemCode = systemCode;
        this.businessCode = businessCode;
        this.businessKey = businessKey;
        this.simpleFields = simpleFields;
        this.combinedFields = combinedFields;
        this.customFields = customFields;
        this.enumFields = enumFields;
    }

//    private List<String> businessKeyValueList = new ArrayList<>();

    public void putObject(String keyValue, Object object) {
        List<Object> list = objectMap.get(keyValue);
        if (CollectionUtils.isEmpty(list)) {
            list = new ArrayList<>();
            objectMap.put(keyValue, list);
        }
        list.add(object);
    }

//    public void addBusinessKeyValue(String keyValue) {
//        businessKeyValueList.add(keyValue);
//    }

    public List<Object> getObjectList() {
        List<Object> objects = new ArrayList<>();
        for (List<Object> list : objectMap.values()) {
            objects.addAll(list);
        }
        return objects;
    }

    public List<String> getKeyList() {
        Set<String> strings = objectMap.keySet();
        return new ArrayList<>(strings);
    }

}
